<?php


namespace app\mini\controller\v1\client;

use app\common\library\MemberVo;
use app\common\logic\MoneyRecordLogic;
use app\mini\controller\Common;
use think\Request;
use think\response\Json;

class MoneyRecord extends Common
{
    public $MoneyRecordLogic;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->MoneyRecordLogic = new MoneyRecordLogic();
    }

    /**
     * 获取状态正常的充值模版
     * @return \think\response\Json
     */
    public function getRechargeTemplate(): Json
    {
        $res = $this->exception(function () {
            return $this->MoneyRecordLogic->getRechargeTemplate();
        });
        return $this->response($res);
    }

    /**
     * 充值
     * @return Json
     */
    public function recharge()
    {
        $res = $this->transException(function () {
            return $this->MoneyRecordLogic->recharge(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 充值回调
     * @return void
     * @throws \EasyWeChat\Kernel\Exceptions\Exception
     */
    public function rechargeNotify()
    {
        $this->MoneyRecordLogic->rechargeNotify()->send();
    }

    /**
     * 消费记录
     * @return Json
     */
    public function consumeRecord(): Json
    {
        $res = $this->exception(function () {
            return $this->MoneyRecordLogic->memberConsumeRecord(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 充值记录
     * @return Json
     */
    public function rechargeRecord(): Json
    {
        $res = $this->exception(function () {
            return $this->MoneyRecordLogic->memberRechargeRecord(request()->param());
        });
        return $this->response($res);
    }


    /**
     * 提现
     * @return Json
     */
    public function withdrawal(): Json
    {
        $res = $this->exception(function () {
            $parans = request()->param();
            $parans['member_id'] = MemberVo::instance()->getMemberId();
            return $this->MoneyRecordLogic->withdrawal($parans);
        });
        return $this->response($res);
    }
}